﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace UI.Forms
{
    public partial class View_whd_0 : FormBase1
    {
        SVC.client.whd_d d = null;
        public View_whd_0()
        {
            InitializeComponent();
        }

        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (gridView1.FocusedRowHandle>=0)
            {
                SVC.client.View_whd_d_0 vd = gridView1.GetRow(gridView1.FocusedRowHandle) as SVC.client.View_whd_d_0;
                if (vd!=null)
                {
                    d=my.bw.whd_dBydid_Get(vd.did,my.ACID);
                    lb_did.Text = d.did.ToString();
                    te_add.Text = d.address;
                    te_dk.Text = d.DK;
                    te_fsp.Text = d.fsp;
                    te_jlxx.Text = d.jlxx;
                    te_slno.Text=d.slno;
                    te_username.Text=d.ClientName;
                    te_wntc.Text=d.wntc;
                    te_yfxx.Text=d.thfyxx;
                    te_cust1.Text = d.cust1;
                    te_cust2.Text = d.cust2;
                    cbe_isyc.EditValue=d.pdsfyc;
                    btn_save.Enabled = btn_savenext.Enabled = true;
                }
                else
                {
                    d = null;
                    lb_did.Text = "";
                    te_add.Text = "";
                    te_dk.Text = "";
                    te_fsp.Text = "";
                    te_jlxx.Text = "";
                    te_slno.Text = "";
                    te_username.Text = "";
                    te_wntc.Text = "";
                    te_yfxx.Text = "";
                    te_cust1.Text = te_cust2.Text = "";
                    cbe_isyc.EditValue = "";
                    btn_save.Enabled = btn_savenext.Enabled = false;
                }
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            DateTime? sd = null;
            DateTime? ed = null;
            Guid? infoempid=null;
            if (dateselect1.de_sd.EditValue!=null&&dateselect1.de_ed.EditValue!=null)
	        {
                sd=dateselect1.de_sd.DateTime;
                ed=dateselect1.de_ed.DateTime;
	        }
            if (lookUpEdit1.EditValue!=null)
	        {
                infoempid=new Guid(lookUpEdit1.EditValue.ToString());
	        }

            gridControl1.DataSource = my.bw.View_whd_d_0_get_pid(te_pid.Text,sd ,ed,infoempid , 0, my.ACID);
        }

        private void View_whd_0_Load(object sender, EventArgs e)
        {
            
            lookUpEdit1.Properties.DataSource = my.bw.View_Emp_lite_List("", my.ACID);
            lookUpEdit1.EditValue = my.emp_lite.EmplID;
            lookUpEdit1.Properties.ReadOnly = true;
            dateselect1.lue_date.Properties.DataSource = my.dts;
            dateselect1.lue_date.EditValue = -1;
        }

        private void btn_save_Click(object sender, EventArgs e)
        {
            d.address = te_add.Text;
            d.DK = te_dk.Text;
            d.pdsfyc = cbe_isyc.Text;
            d.thfyxx = te_yfxx.Text;
            d.wntc = te_wntc.Text;
            d.fsp = te_fsp.Text;
            d.jlxx = te_jlxx.Text;
            d.opdate = DateTime.Now;
            d.cust1 = te_cust1.Text;
            d.cust2 = te_cust2.Text;
            string r = my.bw.whd_d_Update(d, my.ACID);
            if (string.IsNullOrEmpty(r))
            {
                Comm.ShowInfo("保存数据成功！");
            }
            else
            {
                Comm.ShowErorr(r);
            }
        }

        private void btn_savenext_Click(object sender, EventArgs e)
        {
            d.address = te_add.Text;
            d.DK = te_dk.Text;
            d.pdsfyc = cbe_isyc.Text;
            d.thfyxx = te_yfxx.Text;
            d.wntc = te_wntc.Text;
            d.fsp = te_fsp.Text;
            d.jlxx = te_jlxx.Text;
            d.opdate = DateTime.Now;
            d.cust1 = te_cust1.Text;
            d.cust2 = te_cust2.Text;
            d.state = 1;
            string r = my.bw.whd_d_Update(d, my.ACID);
            
            if (string.IsNullOrEmpty(r))
            {
                Comm.ShowInfo("保存数据成功！并已设置为已补全状态。");
                gridView1.DeleteRow(gridView1.FocusedRowHandle);

            }
            else
            {
                Comm.ShowErorr(r);
            }
        }

        private void btn_wc_Click(object sender, EventArgs e)
        {
            d.opdate = DateTime.Now;
            d.state = -1;
            string r = my.bw.whd_d_Update(d, my.ACID);
            if (string.IsNullOrEmpty(r))
            {
                Comm.ShowInfo("已设置为完成状态。");
                gridView1.DeleteRow(gridView1.FocusedRowHandle);

            }
            else
            {
                Comm.ShowErorr(r);
            }
        }

        private void btn_allWC_Click(object sender, EventArgs e)
        {

        }
    }
}